/*
 * @Author: your name
 * @Date: 2021-05-12 19:58:46
 * @LastEditTime: 2021-05-12 21:32:35
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \blog-server\middleware\resource.js
 */
const createError = require('http-errors')
const { classify } = require('inflection')

module.exports = options => {
  return async (req, res, next) => {
    // console.log(req)
    const modelName = classify(req.params.resource)
    try {
      req.Model = require(`../models/${modelName}`)
      next()
    } catch (err) {
      next(createError(404))
    }

  }
}